<template>
  <div class="p-4">
    <BasicTable @register="registerTable" :dataSource="dataSource">
      <template #tableTitle>
        <slot name="message">
          {{ t('title', { length: dataSource.length }) }}
          <a-divider type="vertical" />
          <a @click="loadDate">{{ t('refresh') }}</a>
        </slot>
      </template>
    </BasicTable>
  </div>
</template>
<script lang="ts" name="monitor-trace" setup>
  import { onMounted, ref } from 'vue';
  import { BasicTable, useTable } from '/@/components/Table';
  import { getActuatorList } from './trace.api';
  import { columns } from './trace.data';

  import { useI18n } from '/@/hooks/web/useI18n';
  const { t } = useI18n('monitor.trace');
  const dataSource = ref<any[]>([]);

  const [registerTable] = useTable({
    columns,
    showIndexColumn: false,
    bordered: true,
    rowKey: 'id',
  });

  function loadDate() {
    getActuatorList().then((res) => {
      let filterData: any[] = [];
      for (let d of res.traces) {
        if (d.request.method !== 'OPTIONS' && d.request.uri.indexOf('httptrace') === -1) {
          filterData.push(d);
        }
      }
      dataSource.value = filterData;
    });
  }

  onMounted(() => {
    loadDate();
  });
</script>
